package com.itheima.tliaswebmanagement.controller;

import com.github.pagehelper.Page;
import com.itheima.tliaswebmanagement.pojo.common.PageResult;
import com.itheima.tliaswebmanagement.pojo.common.Result;
import com.itheima.tliaswebmanagement.pojo.dto.StudentPageQueryDTO;
import com.itheima.tliaswebmanagement.pojo.entity.Student;
import com.itheima.tliaswebmanagement.pojo.vo.EmpVO;
import com.itheima.tliaswebmanagement.pojo.vo.StudentVO;
import com.itheima.tliaswebmanagement.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description StudentController
 * @Author ziguan ling
 * @Date 2025--01--20
 */

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping
    public Result studentListQuery(StudentPageQueryDTO studentPageQueryDTO) {
        log.info("分页查询{}", studentPageQueryDTO);
        PageResult<StudentVO> pageResult = studentService.studentListQuery_s(studentPageQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result addStudent(@RequestBody Student student) {
        log.info("添加学员:{}", student);
        studentService.addStudent_s(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id) {
        log.info("根据id查询:{}", id);
        StudentVO studentVO = studentService.queryById_s(id);
        return Result.success(studentVO);
    }

    @PutMapping
    public Result updateStudent(@RequestBody Student student) {
        log.info("修改学员:{}", student);
        studentService.updateStudent_s(student);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result removeBatchStudent(@PathVariable List<Integer> ids) {
        log.info("批量删除学员:{}", ids);
        studentService.removeBatchStudent_s(ids);
        return Result.success();
    }


    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id ,@PathVariable Integer score){
        log.info("违规处理:{}{}",id,score );
        studentService.violation_s(id, score);
        return Result.success();
    }
}















